package LC.nums.minSubArrayLen;

public class LC209 {
    public static void main(String[] args) {
        int[] ints = {1, 2, 3, 4, 5};
        int target = 11;    //3
        System.out.println(minSubArrayLen(target, ints));
    }

    /**
     * @param target
     * @param nums
     * @return
     */
    public static int minSubArrayLen(int target, int[] nums) {
        int low = 0, high = 0, min = Integer.MAX_VALUE;
        int sum = 0;
        while (high < nums.length) {
            sum = sum + nums[high++];
            while (sum >= target) {
                min = Math.min(min, high - low);
                sum = sum - nums[low++];
            }
        }
        if (min == Integer.MAX_VALUE) return 0;
        else return min;
    }

}
